import { Session } from '@/generated/graphql'
import { defineStore } from 'pinia'

/**
 * 用户课程会话相关hook
 *
 *
 */

interface SessionHook {
  session?: Session
}

export const useSession = defineStore({
  id: 'course-session',
  persist: {
    storage: sessionStorage
  },
  state: (): SessionHook => ({
    session: undefined
  }),
  actions: {
    setSession(session: Session | undefined | null) {
      if (session) {
        this.$patch({
          session
        })
      }
    }
  }
})
